#!/usr/bin/env python
# coding=UTF-8
import os
import csv
from blogParser import BlogParser

fieldnames = ['title', 'date', 'content', 'tags','author']
dict_writer = csv.DictWriter(file('blog.csv', 'wb'), fieldnames=fieldnames)
#dict_writer.writerow(fieldnames) # CSV第一行需要自己加入
top = 'origin'
for root, dirs, files in os.walk(top, topdown=False):
    for name in files:
        if name.endswith('html'):
            parser=BlogParser()
            parser.feed(open(os.path.join(root, name)).read())
            dict_writer.writerow({'title':parser.title,'date':parser.datetime().isoformat("-").replace(":","-"),'content':parser.content,'tags':parser.category,'author':'wwwppp0801@gmail.com'}) # rows就是表单提交的数据

